<?php
// $Id$
/**
 * @file featuresreport.drush.inc
 * Features_report module drush integration.
 */

/**
 * Implementation of hook_drush_command().
 * 
 * @See drush_parse_command() for a list of recognized keys.
 *
 * @return
 *   An associative array describing your command(s).
 */
function featuresreport_drush_command() {
  $items = array();

  $items['features-report'] = array(
    'callback' => 'features_command_report',
    'description' => "Build a report.",
    'arguments' => array(
      'feature' => 'Un rapport sur integration continue des features',
    ),
    'drupal dependencies' => array('features'),
    'aliases' => array('fr'),    
  );  
  return $items;
}

/**
 * Implementation of hook_drush_help().
 */
function featuresreport_drush_help($section) {
  switch ($section) {
    case 'drush:features-report':
      return dt("List all elements wich are not part from a features");
  }
}

/**
 * Show elements that are not yet inside a features for a given component 
 */
function features_command_report() {
  
  module_load_include('inc', 'featuresreport', 'elements_in_database');
  
  $components = func_get_args();
  // if no args, show all the components
  if(count($components) == 0) {
    $components = featuresreport_get_components();
  }
  
  $report = array();

  foreach($components as $component) {
    $report[$component] = featuresreport_component_diff($component);
  }
  
  // for each component (content, imagecache, views etc...)
  // we show elements that are not yet inside a features
  foreach ($report as $component => $elements) {
    foreach ($elements as $key => $element) {
      if ($element && $key !== 'state') {
        $string =  sprintf('features[%s][] = "%s"', $component, $element);
        drush_print($string);  
      }
    }
  }
}